/**
 * Project: complex.cs
 * 
 * File Created at 2010-6-30
 * $Id$
 * 
 * Copyright 2008 Alibaba.com Croporation Limited.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * Alibaba Company. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with Alibaba.com.
 */
package cs.myself;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @description:socket服务端
 * @author gaoliang
 * @date 2010-6-30
 * @version 1.0
 */
public class server {
    public static void main(String[] args) {
        try {
            //创建ServerSocket,端口998
            ServerSocket serverSocket = new ServerSocket(998);
            while(true){
                //侦听并接受到此serverSocket的连接
                Socket socket = serverSocket.accept();
                //输出流设置到标准输出流
                OutputStream out = new DataOutputStream(System.out);
                //读取socket的输入流
                InputStream  in = new DataInputStream(socket.getInputStream());
                byte[] bRead = new byte[1024];
                int iRead;
                while ((iRead = in.read(bRead)) != -1) {
                    //写入输出流
                    out.write(bRead,0,iRead);
                }
                socket.close();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
